#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      LL n,p;cin>>n>>p;
      for(LL i=1;i<=n;i++) cin>>a[i];
      LL ans=0;

      for(LL i=1;i<=n;i++){
          LL minval=a[i];LL gcd=a[i];
          LL cnt=0;
          for(LL j=i;j<=n;j++){
          ///   cout<<"\n";
          ///   cout<<"i="<<i<<" "<<"j="<<j<<"\n";
             minval=min(minval,a[j]);
          ///   cout<<"gcd="<<gcd<<" "<<"a["<<j<<"]="<<a[j]<<"\n";
             gcd=__gcd(gcd,a[j]);
         ///    cout<<"gcd="<<gcd<<"\n";
             if(minval==gcd){
                cnt++;
                if(j==n){
                    ans+=min((j-i)*p,minval);
                }
                continue;
             }
             else{
                if(cnt>=2){
                    ans+=min( (cnt-1)*p,minval*(cnt-1));
                }
                else ans+=(j-i+1)*p;
                i=j-1;
                break;
             }
          }
        ///  cout<<"\n";
         //// cout<<"ans="<<ans<<"\n";
      }
      cout<<ans<<"\n";
   }
   return 0;
}
